home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 8 / Power CD-ROM 8.iso / prgmming / oldutil / translat.asm < prev    next >
Encoding:
Assembly Source File  |  1994-12-10  |  3.6 KB  |  169 lines

  1.     Name translat
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a file and changes each
  7.     sentence into the individual words, one word per line.
  8.     Only alphabetic characters are retained - no case changes are
  9.     performed.
  10.  
  11. /
  12. ;===================================================================
  13. code    segment    public
  14. ;===================================================================
  15. ;
  16. ;    command line is at 80h of psp - first byte is length
  17. ;
  18.     org    80h
  19. parmsize    db    ?
  20. parm        db    7fh dup (?)
  21. ;
  22. ; .com starts at 100h - but must jump around any data area
  23. ;
  24.     org    100h            ; com file starts here
  25.     assume    cs:code,ds:code,es:code
  26. translat proc far
  27.     jmp    clear
  28. ;===================================================================
  29. ;
  30. ; data area for .com programs
  31. ;
  32. bufsiz        equ    80    ; hadn't better be words this long!
  33. inchar      db    ?
  34. count        dw    0
  35. crlf        db    13,10    ; end of line string
  36. ;
  37. ;===================================================================
  38. clear:
  39. ;
  40. ; start of actual code is here (clear)
  41. ;
  42.     mov    ah,30h        ; get dos version
  43.     int    21h
  44.     cmp    al,2        ; must be at least 2.0
  45.     jae    xxxx
  46.     jmp    exit
  47. ;
  48. ; release uneeded memory
  49. ;
  50. xxxx:
  51.     mov    bx,offset buffer[512]    ; 256 byte buffer
  52.     mov    sp,bx            ; + 256 byte local stack
  53.     mov    cx,4
  54.     sar    bx,cl
  55.     inc    bx        ; paragraphs needed = end/16 + 1
  56.     mov    ah,4ah        ; SETBLOCK
  57.     int    21h
  58. ;
  59. ; Read a character.  If it is a-z or A-Z copy it to the output buffer
  60. ; and increment count.  If not, send the output buffer and enter
  61. ; bypass loop until alpha character is read again.
  62. ;
  63. ;
  64.     mov    di,offset buffer    ; set up output pointer
  65. again:
  66. ;
  67. ; read a character
  68. ;
  69.     xor    bx,bx        ; zero is handle of standard input
  70.     mov    cx,1h        ; get 1 character
  71.     mov    dx,offset inchar
  72.     mov    ah,3fh        ; read a file/device function
  73.     int    21h        ; invoke the function
  74. ;
  75. ; if carry set of ax=0 exit
  76. ;
  77.     jc    oops        ; i/o error
  78.     and    ax,ax        ; set flags
  79.     jz    oops        ; eof
  80. ;
  81. ; Now check for alpha character.
  82. ;
  83.     mov    al,inchar
  84.     call     isalpha        ; proc sets carry flag if not alpha
  85.     jc    output
  86. ok:
  87.     inc    count
  88.     stosb
  89.     jmp    again
  90. output:
  91.     mov    bx,1h        ; standard output handle
  92.     mov    dx,offset buffer
  93.     mov    cx,count    ; get # of char to output
  94.     mov    ah,40h        ;
  95.     int    21h        ; call dos output function
  96.     call outcrlf
  97. skip:
  98. ;
  99. ; read a character until alphabetic.
  100. ;
  101.     xor    bx,bx        ; zero is handle of standard input
  102.     mov    cx,1h        ; get 1 character
  103.     mov    dx,offset inchar
  104.     mov    ah,3fh        ; read a file/device function
  105.     int    21h        ; invoke the function
  106. ;
  107. ; if carry set of ax=0 exit
  108. ;
  109.     jc    oops        ; i/o error
  110.     and    ax,ax        ; set flags
  111.     jz    oops        ; eof
  112. ;
  113. ; now check it - if alpha, reset else skip again
  114. ;
  115.     mov    al,inchar
  116.     call    isalpha
  117.     jc    skip
  118. ;
  119. ; character is alpha - reset buffer and jump to top again.
  120. ;
  121.     mov    count,1h    ; reset count
  122.     mov    di,offset buffer     ; reset buffer
  123.     stosb
  124.     jmp    again        ; repeat cycle
  125. oops:
  126.     cmp    count,0h    ; if something in buffer, output it.
  127.     jz    exit
  128. ;
  129.     mov    bx,1h        ; standard output handle
  130.     mov    dx,offset buffer    ;
  131.     mov    cx,count    ; get # of char to output
  132.     mov    ah,40h        ;
  133.     int    21h        ; call dos output function
  134.     call    outcrlf
  135. exit:
  136.     int    20h        ; return to dos
  137. translat    endp
  138. ;
  139. ;
  140. isalpha    proc    near
  141.     stc            ; assume bad
  142.     cmp    al,'A'        ; if <A or >z then bad
  143.     jb    notalpha    ;
  144.     cmp    al,'z'
  145.     ja    notalpha
  146.     cmp    al,'Z'        ; if <=Z or >=a then ok
  147.     jbe    yesalpha
  148.     cmp    al,'a'
  149.     jb     notalpha
  150. yesalpha:
  151.     clc
  152. notalpha:
  153.     ret
  154. isalpha    endp
  155. ;
  156. outcrlf    proc    near
  157.     mov    bx,1h        ; standard output handle
  158.     mov    dx,offset crlf      ;
  159.     mov    cx,2h       ; get # of char to output
  160.     mov    ah,40h        ;
  161.     int    21h        ; call dos output function
  162.     ret
  163. outcrlf    endp
  164. ;
  165. buffer    label    near
  166. ;
  167. code    ends
  168.     end    translat
  169.